﻿using System;
using System.Windows;

namespace ResortManager
{
    /// <summary>
    /// Interaction logic for wndUpdateDetails.xaml
    /// </summary>
    public partial class wndUpdateDetails : Window
    {
        private pgLookupTrans m_pgTrans;
        private pgUpdateDetails m_pgDetail;

        private bool m_bIsAdmin;
        public bool IsAdmin
        {
            get { return m_bIsAdmin; }
            set
            {
                m_bIsAdmin = value;
                grdUpdateDetails.Children.Clear();
                if (m_bIsAdmin)
                {
                    grdUpdateDetails.Children.Add(m_pgTrans);
                    m_pgTrans.UpdateData();
                    btnNext.Visibility = Visibility.Visible;
                }
                else
                {
                    grdUpdateDetails.Children.Add(m_pgDetail);
                    btnNext.Visibility = Visibility.Hidden;
                }
            }
        }

        private long m_lEditingTransID;
        public long EditingTransID
        {
            get { return m_lEditingTransID; }
            set
            {
                m_lEditingTransID = value;
                m_pgDetail.EditingTransactionID = m_lEditingTransID;
            }
        }

        private bool m_bIsDeletedAll = false;
        public wndUpdateDetails()
        {
            InitializeComponent();
            m_pgDetail = new pgUpdateDetails();
            m_pgTrans = new pgLookupTrans();
            m_pgDetail.TransactionDeleted += new EventHandler(m_pgDetail_TransactionDeleted);
        }

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            base.OnClosing(e);
            this.DialogResult = m_bIsDeletedAll ? false : true;
        }



        void m_pgDetail_TransactionDeleted(object sender, EventArgs e)
        {
            m_bIsDeletedAll = true;
            Close();
        }

        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            if (m_pgTrans.SelectedTransaction != null)
            {
                EditingTransID = m_pgTrans.SelectedTransaction.TransactionID;
                IsAdmin = false;
            }
        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
